<ui:composition template="/WEB-INF/templates/main-template.xhtml"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

	<ui:define name="sidebar">
		<ui:include src="/WEB-INF/templates/public-sidebar.xhtml" />
	</ui:define>
	<ui:define name="content">
		<h:form>
		<p:growl />
		<h:panelGrid>
		 <h:outputText value= "#{msg['services.label.heading']} " styleClass="outputTextTitle" />
			<h:panelGrid columns="3">
				<h:outputLabel value="Module " />
				<h:outputLabel value=" : " />
				<p:selectOneMenu value="#{servicesBean.selectedModuleId}" styleClass="adminSelectOneMenuWidth">
						<f:selectItems value="#{servicesBean.modulesMap}"/>
						<p:ajax event="change" listener="#{servicesBean.moduleChangeListener}" update="@form"/>
					</p:selectOneMenu>
				<h:outputLabel value="Service "  />
				<h:outputLabel value=" : " />				
				<p:selectOneMenu label="asasa"  value="#{servicesBean.selectedServiceId}"  styleClass="adminSelectOneMenuWidth">	
									<f:selectItem itemLabel="Select a service" itemValue=""/>
						<f:selectItems value="#{servicesBean.servicesMap}"/>
						<p:ajax event="change" listener="#{servicesBean.serviceChangeListener}" update="@form"/>
				</p:selectOneMenu>
			</h:panelGrid>
			<h:panelGrid>
			
				<p:panel id="assignPanel" style="width: 100%" rendered="#{servicesBean.detailsForService}">
				
				<h:outputLabel value="Details for " styleClass="outputTextSubTitle"/>
					<h:panelGrid rendered="#{servicesBean.detailsForService}" >
					<h:panelGrid columns="3"  cellspacing="10" >
						<h:outputLabel value="Service Name " />
						<h:outputLabel value=" : " />
						<p:inplace>
							<p:inputText value="#{servicesBean.selectedService.serviceName}" />
						</p:inplace>

						<h:outputLabel value="Display Name " />
						<h:outputLabel value=" : " />
						<p:inplace>
							<p:inputText value="#{servicesBean.selectedService.displayName}" />
						</p:inplace>

						<h:outputLabel value="Description " />
						<h:outputLabel value=" : " />
						<p:inplace>
							<p:inputTextarea value="#{servicesBean.selectedService.description}" />
						</p:inplace>

					</h:panelGrid>

					<p:dataTable value="#{servicesBean.resourcesAvailableInService}" var="row" rowKey="#{row.resourceId}" binding="#{servicesBean.availableResourcesTable}"   >
						<p:column>
							<f:facet name="header">
								<h:outputText value="Resource Name" />
							</f:facet>
							<h:outputText value="#{row.resourceName}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="File Name" />
							</f:facet>
							<h:outputText value="#{row.fileName}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Display Name" />
							</f:facet>
							<h:outputText value="#{row.displayName}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Description" />
							</f:facet>
							<h:outputText value="#{row.description}" />
						</p:column>
						<p:column style="text-align: center; width: 30px;">
						<p:commandButton icon="ui-icon-close" title="Remove from list"
							actionListener="#{servicesBean.removeService}"
							update="@form" style="padding: 0"/>
					</p:column>

					</p:dataTable>

					<p:commandButton value="Available Resources in Module" actionListener="#{servicesBean.availableResourcesToServiceDisplay}" ajax="false"/>
				</h:panelGrid>
				
				<h:panelGrid cellspacing="10" rendered="#{servicesBean.availableResources}">
					<p:dataTable value="#{servicesBean.resourcesAvailableInModule}" var="row" selectionMode="multiple" rowKey="#{row.resourceId}" selection="#{servicesBean.selectedResources}">
						<p:column>
							<f:facet name="header">
								<h:outputText value="Resource Name" />
							</f:facet>
							<h:outputText value="#{row.resourceName}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="File Name" />
							</f:facet>
							<h:outputText value="#{row.fileName}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Display Name" />
							</f:facet>
							<h:outputText value="#{row.displayName}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Description" />
							</f:facet>
							<h:outputText value="#{row.description}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Add" />
							</f:facet>
						</p:column>

					</p:dataTable>
					<p:commandButton value="Add Resources" style="float: right;" actionListener="#{servicesBean.addResourcesToServiceDisplay}" ajax="false"/>
					<h:outputText value="Assigned Resouces Details"	styleClass="outputTextTitle" style="font-size: 16px;"/>

					<p:dataTable value="#{servicesBean.assignResources}" var="row" rowKey="#{row.resourceId}" binding="#{servicesBean.assignedResourcesTable}" >
						<p:column>
							<f:facet name="header">
								<h:outputText value="Resource Name" />
							</f:facet>
							<h:outputText value="#{row.resourceName}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="File Name" />
							</f:facet>
							<h:outputText value="#{row.fileName}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Display Name" />
							</f:facet>
							<h:outputText value="#{row.displayName}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="Description" />
							</f:facet>
							<h:outputText value="#{row.description}" />
						</p:column>
						<p:column>
							<f:facet name="header">
								<h:outputText value="FirstPage" />
							</f:facet>
							<p:selectBooleanCheckbox value="#{row.selected}"/>
						</p:column>
						<p:column style="text-align: center; width: 30px;">
						<p:commandButton icon="ui-icon-close" title="Remove from list"
							actionListener="#{servicesBean.removeService}"
							update="@form" style="padding: 0"/>
					</p:column>

					</p:dataTable>

					<p:commandButton value="Save" actionListener="#{servicesBean.updateService}" update="@form"/>
					</h:panelGrid>
		        	</p:panel>
		        	</h:panelGrid>	
		        	</h:panelGrid>
		</h:form>
	</ui:define>
</ui:composition>

